package live.jialing.sip.message.box.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import live.jialing.core.beanvalidator.Second;
import live.jialing.data.core.JpaDomainEntity;
import live.jialing.sip.message.box.vo.Receiver;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 发件箱
 */
@Setter
@Getter
@ToString
@Entity
@Table(name = "message_out_box")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "receiver_category", discriminatorType = DiscriminatorType.STRING, length = 30)
@DiscriminatorValue("normal")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = OutBox.class)
public class OutBox extends JpaDomainEntity<Long> {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(message = "id不能为空", groups = {Second.class})
    private Long id;

    /**
     * 发件人userId
     */
    private Long sender;

    /**
     * 收件人
     * @see live.jialing.sip.message.box.vo.Receiver
     */
    private String receiver;

    /**
     * 消息
     */
    @OneToOne(fetch = FetchType.LAZY,optional = false)
    @JoinColumn(name = "info_id")
    private Information information;
}
